// test_cors_config.js - 测试CORS配置
const express = require('express');
const cors = require('cors');

const app = express();

const corsOptions = {
  origin: [
    'http://localhost:5174',
    'http://127.0.0.1:5174', // 添加127.0.0.1支持
    'http://124.223.42.84:65174', // 你的内网穿透地址
    'http://localhost:5173',
    'http://localhost:3000'
  ],
  credentials: true,
  optionsSuccessStatus: 200
};

app.use(cors(corsOptions));
app.use(express.json());

app.post('/test', (req, res) => {
  res.json({ message: 'CORS test successful' });
});

app.listen(3001, () => {
  console.log('CORS测试服务器运行在 http://localhost:3001');
});